package com.walsai.pcsys.core.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;


@Entity
public class User extends BaseObject implements Serializable{
	private static final long serialVersionUID = 334172384192384217L;
	
	public final static int ROLE_ADMIN = 0;
	public final static int ROLE_USER = 1;
	public final static int ROLE_ANONYMOUS = 2;
	

    public static int getROLE_ADMIN() {
		return ROLE_ADMIN;
	}

	public static int getROLE_USER() {
		return ROLE_USER;
	}

	public static int getROLE_ANONYMOUS() {
		return ROLE_ANONYMOUS;
	}

	private String username;                    // required
    private String password;                    // required
    private String confirmPassword;
    private String passwordHint;
    private String firstName;                   // required
	private String middleName;
    private String lastName;                    // required
    private String email;                       // required; unique
    private int role;
	
	@Id
	@Column(nullable=false, length=50, unique=true)
	public String getUsername() {
		return username;
	}

	@Column(nullable=false, length=32)
	public String getPassword() {
		return password;
	}

	@Transient
	public String getConfirmPassword() {
		return confirmPassword;
	}
	
	@Column(name="password_hint", nullable=false)
	public String getPasswordHint() {
		return passwordHint;
	}
	
	@Column(name="first_name", nullable=false, length=50)
	public String getFirstName() {
		return firstName;
	}

	@Column(name="middle_name", length=50)
	public String getMiddleName() {
		return middleName;
	}

	@Column(name="last_name", nullable=false, length=50)
	public String getLastName() {
		return lastName;
	}

	@Column(nullable=false, unique=true)
	public String getEmail() {
		return email;
	}

	@Column(nullable=false)
	public int getRole() {
		return role;
	}	
	


	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	public void setPasswordHint(String passwordHint) {
		this.passwordHint = passwordHint;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public void setEmail(String email) {
		this.email = email;
	}
    
	public void setRole(int role) {
		this.role = role;
	}

	@Override
	public boolean equals(Object o) {
        boolean result = false;
        if (o != null && getClass() == o.getClass()) {
            final User p = (User) o;
            if (this.username == p.username) {
                result = true;
            }
        }
        return result;
	}

	@Override
	public int hashCode() {
		return  this.username.hashCode();
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return null;
	}
}